package com.hmdp.config;

import com.hmdp.utils.LoginInterceptor;
import com.hmdp.utils.RefreshIntercepter;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class MVCconfig implements WebMvcConfigurer {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录拦截器
        registry.addInterceptor(new LoginInterceptor())//添加拦截器
                .addPathPatterns("/**")
                .excludePathPatterns("/user/code",
                                     "/user/login",
                        "/blog/hot",
                        "/shop/**",
                        "/shop-type/**",
                        "/upload/**",
                        "/druid/**",
                        "/voucher/**")
                .order(1);

       //刷新拦截器
        registry.addInterceptor(new RefreshIntercepter(stringRedisTemplate))//添加刷新拦截器
                .addPathPatterns("/**")
                .order(0);//数字越小优先级越高，优先执行
    }
}
